var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
$(function(){
	initSmPages();
	window.onresize = function () {
		initSmPages();
	};
	pagebtns();
	initStudent();
});
function initStudent(){
	var userkey = $("#user-name",parent.document).attr("key");
	var usercode = $("#user-name",parent.document).attr("code");
	var data = {
			cmd:"getStudentByUserCode",
			model:"user",
			userKey:userkey,
			data:{
				usercode:usercode
			},
			remark:""					
	};
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1){
			var list = res.data;
			var imgContent = "";
			for(var i = 0; i < list.length; i++){
				if(i == 0){
					imgContent += "<div class='students-choice students-choice-select' imei='"+list[i].imei+"' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
				}else{
					imgContent += "<div class='students-choice' imei='"+list[i].imei+"' classcode='" + list[i].classcode + "' studentcode='" + list[i].studentcode + "' name = '"+list[i].name+"' title = '"+list[i].name+"'><div class='students-choice-img'><img src=\"../../../../../"+ServiceName+list[i].headimg+"\" width='100%' height='100%'/></div><div  class='students-choice-name'>"+substr(list[i].name,4)+"</div></div>";
				}
			}					
			$(".dialog-students-contents").empty();
			$(".dialog-students-contents").append(imgContent);
			changePage(PageUrl.pterminalUrl);
			$(".students-choice").unbind("click");
		}else{
			$(".dialog-students-contents").empty();
			$(".dialog-students-contents").append("<div class='students-choice students-choice-select'>没有相关信息</div>");
			changePage(PageUrl.pterminalUrl);
		}
	},null,null);
}	
function pagebtns(){
	$(".left-menu").click(function(){
		$(".left-menu-sec").hide();
		if($(this).attr("model") == "终端设置"){
			$("#aterminal-op").show();
			var Hei = $("#aterminal-op .menu-sec").length * $(".menu-sec").height();
			$("#aterminal-op").height(Hei);
		}
	});
	$(".menu-sec").click(function(){
		var model = $(this).attr("title");
		$(".menu-sec").removeClass("menu-sec-select");
		$(this).addClass("menu-sec-select");
		if(model == "终端设置"){
			changePage(PageUrl.pterminalUrl);
		}else if(model == "亲情号"){
			changePage(PageUrl.parentnumUrl);
		}else if(model == "sos号码"){
			changePage(PageUrl.sosnumUrl);
		}else if(model == "白名单"){
			changePage(PageUrl.whitenumUrl);
		}else if(model == "sos报警"){
			changePage(PageUrl.sosUrl);
		}else if(model == "工作时段"){
			changePage(PageUrl.workUrl);
		}else if(model == "隐身时段"){
			changePage(PageUrl.unworkUrl);
		}else if(model == "铃声"){
			changePage(PageUrl.ringUrl);
		}else if(model == "来电设置"){
			changePage(PageUrl.callerUrl);
		}else if(model == "终端留言"){
			changePage(PageUrl.messageUrl);
		}
	});
	$(".dialog-display-btnshow").click(function(){
		$(".dialog-display-btnshow").hide();
		$(".dialog-display-btnhide").show();
		$(".student-choice-classdia").animate({right:"0px"});
	});
	$(".dialog-display-btnhide").click(function(){
		$(".dialog-display-btnshow").show();
		$(".dialog-display-btnhide").hide();
		$(".student-choice-classdia").animate({right:"-120px"});
	});
}
function substr(str,len){
	if(str != undefined){
		if(str.length > len){
			str = str.substring(0,len-2)+"...";
			return str;
		}else{
			return str;
		}
	}else{
		return "";
	}
}
function changePage(pageUrl){
	$("#right-iframe").attr("src",pageUrl);
}
function initSmPages(){
	var bodyRW = $(".index-body",parent.document).width() - $(".body-left").width()-6;
	$(".body-right").width(bodyRW);
	
	var leftCH = $(".body-left").height() - $(".left-title").height()-1;
	$(".left-content").height(leftCH);
}